/**
**************************************************************************************
*Palisma - Secrets of the Illuminati is an open-source 2D RPG                        *
*Copyright (C) 2006, Tony Sparks                                                     *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#pragma once
#include "SDL.h"

#ifdef _WIN32
#include "windows.h"
#endif

#include "glfont2.h"
#include "IRender.h"
#include "TextureLoader.h"
#include "Camera.h"
#include "../Console.h"
#include "FontManager.h"

/**
======================
OpenGL implementation of our Renderer
======================
*/
class GLRender : public IRender
{
public:
    GLRender(void);

    int Init();
	void Shutdown();

	void DrawImage( Image *im, int x, int y);
    void DrawImage( Image *im, int x, int y, float width, float height);
    void DrawSubImage( Image *im, int x, int y, int row, int col);

    void DrawString( int x, int y, const char *s,...);
	void DrawRect( int x, int y, int w, int h );
    void DrawCircle( float radius, int x, int y);
    void DrawLine( const Vector2f &p1, const Vector2f &p2 );
	void FillRect( int x, int y, int w, int h );
    void FillCircle( float radius, int x, int y);

    int GetTextHeight(char c) { 
        return m_fontManager.GetHeight();
    };
    
    int GetTextWidth(char c) { 
        return m_fontManager.GetWidth();  
    };
    /**
    int GetTextHeight(char c){ return 0;};
    int GetTextWidth(char c) { return 0; };
    **/

	void  SetColor( float r, float g, float b, float a=1);
    void  SetColor(Color c);
	Color GetColor();
    void  SetColorEffect( float r, float g, float b, float a=1);
    void  SetColorEffect(Color c);
    Color GetColorEffect();

	void PreRender();
	void PostRender();

    void EnableFog();
    void DisableFog();
    void SetFogDensity(float density);
    void ChangeFogColor(float r, float g, float b, float a=1);
    void ChangeFogColor(Color c);
    Color GetFogColor();

    /*----------------------------------------------------
        Camera
    ----------------------------------------------------*/
    ICamera* GetCamera() { return &m_camera; };
    void SetCamera( ICamera* c ) { /*m_camera = static_cast<Camera>(c))*;*/ };

private:
    SDL_Surface*    screen;
    Camera         m_camera;
    FontManager     m_fontManager;
    
    Color           m_color;
    Color           m_fogColor;
    Color           m_cEffect;
    float           m_fogDensity;
   
    int     m_width,
            m_height;

    /** Take a screeny */
    void CaptureScreen(const std::string &file="");
    /**
     * Screen shot function
     */
    class ScreenShot_f : public ICommand
    {
    public:
        ScreenShot_f() { renderer = NULL; };
        virtual ~ScreenShot_f() {};
        /** Create an ss */
        void Exec(std::string &s) {
            if ( renderer )
                renderer->CaptureScreen( s );
        };

        GLRender* renderer;
    }; friend ScreenShot_f;
    ScreenShot_f screen_f;

public:
    virtual ~GLRender(void);
};
